package com.k.ums.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

/**
 * @Description:
 * @Author: kt
 * @CreateTime: 2022/1/14
 */
@Data
public class ResponseResult {

    private static final String SUCCESS = "200";

    private static final String FAILED = "500";

    private String code;
    private String msg;
    private Object data;

    public ResponseResult() {
    }

    public ResponseResult(String code) {
        this(code, "");
    }

    public ResponseResult(String code, String msg) {
        this(code, msg, null);
    }

    public ResponseResult(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    @JsonIgnore
    public <T> T getRealData() {
        return (T) data;
    }

    public static ResponseResult success() {
        return success("操作成功");
    }

    public static ResponseResult success(String msg) {
        return success(msg, null);
    }

    public static ResponseResult success(Object data) {
        return success("操作成功", data);
    }

    public static ResponseResult success(String msg, Object data) {
        return new ResponseResult(SUCCESS, msg, data);
    }

    public static ResponseResult error() {
        return error("操作失败");
    }

    public static ResponseResult error(String msg) {
        return new ResponseResult(FAILED, msg);
    }
}
